Ext.ns('Ext.manager');

Ext.manager.Panel = Ext.extend(Ext.Panel,{
	buttonAlign:'center',
	closable : true,
	initComponent:function(){
		this.formpanel = new Ext.form.FormPanel({
			items:[
			         
			       {
			       		xtype:'textfield',
			       		fieldLabel:'姓名',
			       		id:this.id+'name',
			       		name:"generalManager.generalmanagername"
			       	},	 
			 {
				xtype:'textfield',
				fieldLabel:'工号',
				id:this.id+'number',
				name:'generalManager.jobnumber',
				blank:false,
			},{
				xtype:'textfield',
				fieldLabel:'电话',
				id:this.id+'phone',
				name:'generalManager.generalmanagerphone',
			},{
				xtype:'textfield',
				fieldLabel:'密码',
				id:this.id+'password',
				name:'generalManager.generalmanagerpassword',
				blank:false,
			}]
		});
		this.items  =  this.formpanel;
		
		this.buttons =[{
						text:'新增管理员',
						iconCls : 'update',
						handler : function(b,e){
							var a = b.findParentBy(function(ct, cmp) { 
								return (ct instanceof Ext.manager.Panel) ? true : false; 
							});
							var c1 = a.formpanel.findById(a.id+'number').getValue();
							var c2 = a.formpanel.findById(a.id+'password').getValue();
							if(c1 =="" || c2 == ""){
								Ext.Msg.alert('提示','请填写资料')
								return ;
							}
							a.formpanel.form.submit({
								url:'generalManager/generalManagerAction!insertGeneralManager',
								success : function(action,form){
									
									var data = Ext.decode(form.response.responseText);
									var a = "新增用户工号为："+data.number+"\n 密码为："+data.passward;
									Ext.Msg.alert("提示",'新增管理员成功！\n'+a);
									a.formpanel.form.reset();
							},		
								failure : function(action,form){
									var data = Ext.decode(form.response.responseText);
									var a;
									if(data.mark == -1){
										a = "工号未填或者工号重复";
									}else
										a = "无操作权限！";
									Ext.Msg.alert("提示",'新增管理员失败！\n'+a);
									a.formpanel.form.reset();
							}
							});
					
							
						}
					}
					]
			Ext.manager.Panel.superclass.initComponent.call(this);
}
})